import { createHashRouter, redirect } from "react-router-dom";
import App from "./App";
import Home from "./pages/home";
import Login from "./pages/login";
import Questions from "./pages/questions";
import { ApiHome } from "@/utils/api";
import User from "./pages/user";

const router = createHashRouter([
  {
    path: "/",
    errorElement: <>404</>,
    element: <App />,

    children: [
      {
        index: true,
        // path: "/home",
        element: <Home></Home>,
        loader(): any {
          const getHomeData = async () => {
            let res = await ApiHome();
            return res.data;
          };
          return { getHomeData };
        },
      },
      {
        path: "/questions",
        element: <Questions></Questions>,
      },
      {
        path: "/user",
        element: <User></User>,
      },
      {
        path: "/login",
        element: <Login></Login>,
      },
    ],
  },
]);

export default router;
